package bp.wf.dts;

import bp.da.DataType;
import bp.en.Method;
import bp.sys.AutoTask;
import bp.sys.AutoTasks;

import java.util.Date;

public class AutoTask_DTS  extends Method {


    @Override
    public Object Do() throws Exception {
        //获得定时任务信息.
        AutoTasks tasks = new AutoTasks();
        tasks.RetrieveAllFromDBSource();

        int nowInt = Integer.parseInt(DataType.dateToStr(new Date(),"HHmm"));

        //比如: 2009
        String strTimes=DataType.dateToStr(new Date(),"yyyy-MM-dd HH:MM");

        // "01 12:01,15 12:01"
        String msg = "";
        for (AutoTask rpt :tasks.ToJavaList())
        {
       // 判断是否达到执行的条件.
            String[] tims = rpt.getTimes().split(",");
            boolean isHave = false;
            for (String s : tims)
            {
                if (strTimes.contains(s) == false)
                    continue;

                isHave = true;
                break;
            }
            if (isHave == false)
                continue;
       // 判断是否达到执行的条件.

            msg += rpt.RunTask();
        }

        return "执行成功." + msg;
    }

    @Override
    public void Init() {

    }

    @Override
    public boolean getIsCanDo() {
        return true;
    }
}
